

void dist(void){
	static int speed=0;
	static int numQuietReads=0;

		if((timer-timer_LastDistCalc)>def_distCalcInterval){
			int a = (vect_data.accel_accum / vect_data.accelDiv)*10;

			if(abs(a)>30){
				speed = a + speed;
				numQuietReads=0;
			}
			else if (abs(speed)>50){
				numQuietReads++;
					float factor = (1/numQuietReads);
					speed = speed*factor;
			}
			else
			{
				speed=0;
			}
			 
			vect_data.dist_accum+=speed;

			timer_LastDistCalc=timer;
			vect_data.accel_accum=0;
			vect_data.accelDiv=0;

			accelArray[idx] = a;
			idx++;

			//Serial.print(speed);
			//Serial.print(" ");
			//Serial.print(a);
			//Serial.println(" ");
		}

		else{
			vect_data.accelDiv++;
			vect_data.accel_accum+=sen_data.accel_x + sin(pitch)*(280);
			vect_data.headDiv++;
			vect_data.heading_accum+=sen_data.magnetom_heading;
		}
}